{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "1bb7c5ac53c3424799802720c81a54d8",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Plot(antialias=3, axes=['x', 'y', 'z'], background_color=16777215, camera=[0.5197843715148425, 0.5197843715148…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\"\"\"Show fenics mesh and displacement solution.\"\"\"\n",
    "########################################################### dolfin\n",
    "from dolfin import *\n",
    "\n",
    "# Create mesh and define function space\n",
    "mesh = UnitCubeMesh(12, 12, 12)\n",
    "V = VectorFunctionSpace(mesh, \"Lagrange\", 1)\n",
    "\n",
    "# Mark boundary subdomains\n",
    "left  = CompiledSubDomain(\"near(x[0], side) && on_boundary\", side=0.0)\n",
    "right = CompiledSubDomain(\"near(x[0], side) && on_boundary\", side=1.0)\n",
    "\n",
    "# Define Dirichlet boundary (x=0 or x=1)\n",
    "c = Constant((0.0, 0.0, 0.0))\n",
    "r = Expression((\n",
    "        \"scale*0.0\",\n",
    "        \"scale*(y0 + (x[1]-y0)*cos(theta) - (x[2]-z0)*sin(theta)-x[1])\",\n",
    "        \"scale*(z0 + (x[1]-y0)*sin(theta) + (x[2]-z0)*cos(theta)-x[2])\",\n",
    "    ), scale=0.5, y0=0.5, z0=0.5, theta=pi/4, degree=2 )\n",
    "bcl = DirichletBC(V, c, left)\n",
    "bcr = DirichletBC(V, r, right)\n",
    "\n",
    "w = TrialFunction(V)  # Incremental displacement\n",
    "v = TestFunction(V)   # Test function\n",
    "u = Function(V)       # Solution\n",
    "\n",
    "solve(inner(grad(w), grad(v)) * dx == inner(c, v) * dx, u, [bcl, bcr])\n",
    "\n",
    "########################################################### vtkplotter\n",
    "from vtkplotter.dolfin import plot\n",
    "\n",
    "plot(u, mode='my displaced mesh please!!', shading='flat', cmap='jet')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
